'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ProjectLendlistCtrl
 * @description
 * # ProjectLendlistCtrl
 * Controller of the jgappApp
 */
angular
  .module("jgappApp")
  .controller("ProjectChooseLendlistCtrl", function (
    Util,
    $scope,
    $routeParams,
    openApi,
    PagingService
  ) {

    // 选择后回传的数据
    $scope.choosePeople = function (index) {
      var item = $scope.taskList.items[index]
      item.selected = !item.selected;
      $scope.selectLists = getSelectedData();
    };
    var getSelectedData = function () {
      var selectedData = $scope.taskList.items.filter(function (item, index) {
        return item.selected;
      });
      return selectedData
    }
    $scope.submit = function () {
      if ($scope.selectLists.length < 1) {
        Util.Toast("请选择借款");
        return
      }
      var relModuleObj = {
        filterData: {}
      }
      relModuleObj.filterData["borrows"] = getPropertyValue();
      Util.savaDataforsearch(relModuleObj);
      Util.goBack();
    }
    var getPropertyValue = function () {
      var selectedData = $scope.selectLists;
      var data = [];
      selectedData.forEach(function (item, index) {
        data.push({
          borrowingId:item.pkId,
          borrowingNo:item.fileNo,
          borrowingPerson:item.userName,
          borrowPurpose:item.borrowPurpose,
          borrowingAmount:item.borrowingAmount,
          reimburseAmount:0
        })
      })
      return data;
    }
    $scope.search = function (input) {
      var param = {
        completion: 1,
        returnStatus: 0
      };

      param.projectId = $routeParams.projectId;
      param.userName = input;
      $scope.taskList = new PagingService(openApi.borrowingList, param);
    };
    $scope.search();
  });
